<?php
class Language {
    private $default;
    private $directory;
    private $data = array();
    private $language_id;
    private $code;

    public function __construct($path, $directory, $default = 'english') {
        $this->directory = $path . $directory;
        $this->default = $path . $default;
        $this->data = array();
    }

    public function setId($language_id){
        $this->language_id = $language_id;
    }    

    public function get_id(){
        return $this->language_id;
    }

    public function setCode($code){
        $this->code = $code;
    }

    public function getCode(){
        return $this->code;
    }

    public function get($key) {
        return (isset($this->data[$key]) ? $this->data[$key] : $key);
    }

    public function load($filename) {
        $file = $this->directory . '/' . $filename . '.php';

        if (file_exists($file)) {
            $_ = array();

            require($file);

            $this->data = array_merge($this->data, $_);

            return $this->data;
        }

        $file = $this->default . '/' . $filename . '.php';

        if (file_exists($file)) {
            $_ = array();

            require($file);

            $this->data = array_merge($this->data, $_);

            return $this->data;
        } else {

            throw new Exception('Error: Could not load language file: ' . $this->directory . '/' . $filename . '.php');
        }
    }
}
?>
